package com.ruoyi.framework.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
/**
 * 描述 Jackson全局转化Long[]类型为String[]，解决js精度丢失问题
 * 作者 ZhangPing
 * 创建时间 2023/9/21 11:25
 */
public class LongArrayToStringArraySerializer extends JsonSerializer<Long[]> {

    public static final LongArrayToStringArraySerializer instance = new LongArrayToStringArraySerializer();

    @Override
    public void serialize(Long[] longs, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String[] strings = new String[longs.length];
        for (int i = 0; i < longs.length; i++) {
            strings[i] = String.valueOf(longs[i]);
        }
        jsonGenerator.writeObject(strings);
    }
}